﻿<UserControl x:Class="EuroManager.Presentation.WebPortal.GameViewer.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:u="clr-namespace:EuroManager.Presentation.WebPortal.GameViewer.Utilities"
    mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="700">
    <UserControl.Resources>
        <BitmapImage x:Key="ball" UriSource="/EuroManager.Presentation.WebPortal.GameViewer;component/Content/Ball.png"/>
        <BitmapImage x:Key="playerBlue" UriSource="/EuroManager.Presentation.WebPortal.GameViewer;component/Content/PlayerBlue.png"/>
        <BitmapImage x:Key="playerRed" UriSource="/EuroManager.Presentation.WebPortal.GameViewer;component/Content/PlayerRed.png"/>
        <BitmapImage x:Key="goalkeeper" UriSource="/EuroManager.Presentation.WebPortal.GameViewer;component/Content/Goalkeeper.png"/>
        <u:BoolToVisibilityConverter x:Key="boolConverter"/>
        <u:NotBoolToVisibilityConverter x:Key="notBoolConverter"/>
        <u:NegateConverter x:Key="negateConverter"/>
        <u:PitchLocationConverter x:Key="pitchXConverter" Size="106.5" ImageSize="820" Margin="91"/>
        <u:PitchLocationConverter x:Key="pitchYConverter" Size="71.5" ImageSize="550" Margin="74"/>
        <u:SelectConverter x:Key="playerImageConverter">
            <u:SelectOption For="Goalkeeper" Use="{StaticResource goalkeeper}"/>
            <u:SelectOption For="Team1FieldPlayer" Use="{StaticResource playerBlue}"/>
            <u:SelectOption For="Team2FieldPlayer" Use="{StaticResource playerRed}"/>
        </u:SelectConverter>
    </UserControl.Resources>
    <Grid Background="White">
        <Canvas>
            <Image Source="/EuroManager.Presentation.WebPortal.GameViewer;component/Content/Pitch.png" Stretch="None"/>
            <ItemsControl ItemsSource="{Binding Players}"
                          Visibility="{Binding HasStarted, Converter={StaticResource boolConverter}}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas Width="1000" Height="700"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RenderTransform>
                                <TranslateTransform X="{Binding X, Converter={StaticResource pitchXConverter}, ConverterParameter=12}"
                                                    Y="{Binding Y, Converter={StaticResource pitchYConverter}, ConverterParameter=13}"/>
                            </Grid.RenderTransform>
                            <Image Source="{Binding PlayerType, Converter={StaticResource playerImageConverter}}">
                                <Image.RenderTransform>
                                    <RotateTransform Angle="{Binding Angle}" CenterX="12" CenterY="13"/>
                                </Image.RenderTransform>
                            </Image>
                            <TextBlock FontFamily="Trebuchet MS" FontSize="8" Foreground="White"
                                       HorizontalAlignment="Center" VerticalAlignment="Center"
                                       Text="{Binding Number}"/>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            <Image Source="{StaticResource ball}"
                   Visibility="{Binding HasStarted, Converter={StaticResource boolConverter}}">
                <Image.RenderTransform>
                    <TranslateTransform X="{Binding Ball.X, Converter={StaticResource pitchXConverter}, ConverterParameter=6}"
                                        Y="{Binding Ball.Y, Converter={StaticResource pitchYConverter}, ConverterParameter=6}"/>
                </Image.RenderTransform>
            </Image>
        </Canvas>
        <TextBlock FontSize="32" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,73,0"
                   Text="{Binding Clock.Minutes, StringFormat=00}"
                   Visibility="{Binding HasStarted, Converter={StaticResource boolConverter}}"/>
        <TextBlock FontSize="32" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,60,0"
                   Text=":"
                   Visibility="{Binding HasStarted, Converter={StaticResource boolConverter}}"/>
        <TextBlock FontSize="32" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,20,0"
                   Text="{Binding Clock.Seconds, StringFormat=00}"
                   Visibility="{Binding HasStarted, Converter={StaticResource boolConverter}}"/>
        <TextBlock FontSize="32" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,10,30,0"
                   Text="{Binding Score.Score1}"
                   Visibility="{Binding HasStarted, Converter={StaticResource boolConverter}}"/>
        <TextBlock FontSize="32" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,10,0,0"
                   Text=":"
                   Visibility="{Binding HasStarted, Converter={StaticResource boolConverter}}"/>
        <TextBlock FontSize="32" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="30,10,0,0"
                   Text="{Binding Score.Score2}"
                   Visibility="{Binding HasStarted, Converter={StaticResource boolConverter}}"/>
        <Button Content="Start" Width="80" Height="40"
                    Click="OnStartClick" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,10"
                    Visibility="{Binding HasStarted, Converter={StaticResource notBoolConverter}}"/>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,10"
                    Visibility="{Binding IsActive, Converter={StaticResource boolConverter}}">
            <Button Content="&lt;&lt; RW" Width="80" Height="40"
                    Command="{Binding RewindCommand}"
                    IsEnabled="{Binding IsRewinding, Converter={StaticResource negateConverter}}"/>
            <Button Content="Pause ||" Width="80" Height="40"
                    Command="{Binding PauseCommand}"
                    IsEnabled="{Binding IsPaused, Converter={StaticResource negateConverter}}"/>
            <Button Content="Play &gt;" Width="80" Height="40"
                    Command="{Binding PlayCommand}"
                    IsEnabled="{Binding IsPlaying, Converter={StaticResource negateConverter}}"/>
            <Slider Minimum="0.25" Maximum="10" Value="{Binding Speed, Mode=TwoWay}" Width="150" SmallChange="0.2" LargeChange="1.0"/>
        </StackPanel>
    </Grid>
</UserControl>
